﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../../lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script> 
    <script src="../../lib/json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        var DepartmentList = { Rows: [{ "DepartmentID": 1, "DepartmentName": "主席", "DepartmentRemark": null }, { "DepartmentID": 2, "DepartmentName": "研发中心", "DepartmentRemark": null }, { "DepartmentID": 3, "DepartmentName": "销售部", "DepartmentRemark": null }, { "DepartmentID": 4, "DepartmentName": "市场部", "DepartmentRemark": null }, { "DepartmentID": 5, "DepartmentName": "顾问组", "DepartmentRemark": null}], Total: 5 };
        var sexData = [{ id: 1, text: '男' }, { id: 2, text: '女'}];
        var data = { Rows: [{ "__status": null, "ID": 71, "DepartmentID": 4, "RealName": "44444444444441", "DepartmentName": "市场部", "Sex": 2, "Age": 6, "IncomeDay": new Date(978566400000), "Phone": null, "Address": "啊" }, { "__status": null, "ID": 82, "DepartmentID": 4, "RealName": "名字不能为空", "DepartmentName": "市场部", "Sex": 1, "Age": 18, "IncomeDay": new Date(1303948800000), "Phone": null, "Address": "" }, { "__status": null, "ID": 86, "DepartmentID": 1, "RealName": "网络", "DepartmentName": "主席", "Sex": 2, "Age": 20, "IncomeDay": new Date(1301443200000), "Phone": null, "Address": "" }, { "__status": null, "ID": 88, "DepartmentID": 1, "RealName": "aaass", "DepartmentName": "主席", "Sex": 1, "Age": 12, "IncomeDay": new Date(1293897600000), "Phone": null, "Address": "bbb" }, { "__status": null, "ID": 89, "DepartmentID": 1, "RealName": "bbb", "DepartmentName": "主席", "Sex": 1, "Age": 10, "IncomeDay": new Date(-1860508800000), "Phone": null, "Address": "dff" }, { "__status": null, "ID": 93, "DepartmentID": 5, "RealName": "ab", "DepartmentName": "顾问组", "Sex": 1, "Age": 3, "IncomeDay": new Date(4133980800000), "Phone": null, "Address": "4444" }, { "__status": null, "ID": 95, "DepartmentID": 0, "RealName": "def", "DepartmentName": null, "Sex": 0, "Age": 22, "IncomeDay": new Date(1104566400000), "Phone": null, "Address": "" }, { "__status": null, "ID": 96, "DepartmentID": 0, "RealName": "de", "DepartmentName": null, "Sex": 0, "Age": 23, "IncomeDay": new Date(-599587200000), "Phone": null, "Address": "" }, { "__status": null, "ID": 97, "DepartmentID": 0, "RealName": "d", "DepartmentName": null, "Sex": 0, "Age": 23, "IncomeDay": new Date(978336000000), "Phone": null, "Address": "" }, { "__status": null, "ID": 98, "DepartmentID": 0, "RealName": "c", "DepartmentName": null, "Sex": 0, "Age": 12, "IncomeDay": new Date(980409600000), "Phone": null, "Address": "" }, { "__status": null, "ID": 100, "DepartmentID": 0, "RealName": "a", "DepartmentName": null, "Sex": 0, "Age": 23, "IncomeDay": new Date(980236800000), "Phone": null, "Address": "" }, { "__status": null, "ID": 101, "DepartmentID": 3, "RealName": "名字不能为空", "DepartmentName": "销售部", "Sex": 2, "Age": 20, "IncomeDay": new Date(1301356800000), "Phone": null, "Address": ""}], Total: 12 };
        $(function ()
        {  
            f_initGrid();  
        });
        function f_initGrid()
        {
            $("#maingrid").ligerGrid({
                columns: [
                { display: '主键', name: 'ID', width: 50, type: 'int' },
                { display: '名字', name: 'RealName',
                    editor: { type: 'text' }
                },
                { display: '性别', width: 50,
                    editor: { type: 'select', data: sexData ,valueColumnName:'Sex'},
                    render: function (item)
                    {
                        if (parseInt(item.Sex) == 1) return '男';
                        return '女';
                    }
                },
                { display: '年龄', name: 'Age', width: 50, type: 'int', editor: { type: 'int'} },
                { display: '入职日期', name: 'IncomeDay', type: 'date', width: 100, editor: { type: 'date'} },
                { display: '部门', name: 'DepartmentName', width: 120, isSort: false,
                    editor: { type: 'select', data: DepartmentList.Rows, dataValueField: 'DepartmentID', dataDisplayField: 'DepartmentName', valueColumnName: 'DepartmentID' }
                },
                { display: '地址', name: 'Address',
                    editor: { type: 'text' }, align: 'left', width: 300
                }
                ],
                enabledEdit: true, usePager: false, isScroll: false,
                data:data,
                width: '100%'
            });
        }
        function f_save()
        {
            var manager = $("#maingrid").ligerGetGridManager();
            var data = manager.getData();
            $.post("../../service/EmpDataHandler.ashx?Action=save", [{ name: 'data', value: JSON2.stringify(data)}]
            , function (result)
            {
                if (result == "Y")
                {
                    $.ligerMessageBox.success('提示', '保存成功!', function ()
                    {
                        manager.loadData(true);
                    });
                }
                else
                {
                    $.ligerMessageBox.error('提示', result);
                }
            });
        }
        function deleteRow()
        {
            var manager = $("#maingrid").ligerGetGridManager();
            manager.deleteSelectedRow();
        }
        function addNewRow()
        {
            var manager = $("#maingrid").ligerGetGridManager();
            manager.addRow();
        } 
        function getSelected()
        {
            var manager = $("#maingrid").ligerGetGridManager();
            var row = manager.getSelectedRow();
            alert(JSON.stringify(row));
        }
        function getData()
        {
            var manager = $("#maingrid").ligerGetGridManager();
            var data = manager.getData();
            alert(JSON.stringify(data));
        }
    </script>
</head>
<body>
<!--<a class="l-button" style="width:60px; float:left; margin-left:10px;" onclick="f_save()">保存</a>-->
<a class="l-button" style="width:120px;float:left; margin-left:10px;" onclick="deleteRow()">删除选择的行</a>
<a class="l-button" style="width:100px;float:left; margin-left:10px;" onclick="addNewRow()">添加行</a>

 <div class="l-clear"></div>
    <div id="maingrid" style="margin-top:20px"></div> <br />
       <br />
   <a class="l-button" style="width:120px" onclick="getSelected()">获取选中的值(选择行)</a>
 
   <br />
   <a class="l-button" style="width:120px" onclick="getData()">获取当前的值</a>
  <div style="display:none;">
  
</div>
</body>
</html>
